package main.Q601_700;

import java.util.Arrays;

public class Q611_620 {
    public static void main(String[] args) {
        System.out.println("Question611：有效三角形的个数");
        int[] arr={1,2,3,4,5,6,7};
        System.out.println(new Question611().triangleNumber(arr));
        System.out.println("Question612：");
        System.out.println("Question613：");
        System.out.println("Question614：");
        System.out.println("Question615：");
        System.out.println("Question616：");
        System.out.println("Question617：合并二叉树");
        System.out.println("Question618：");
        System.out.println("Question619：");
        System.out.println("Question620：");
    }
}

class Question611{
    public int triangleNumber(int[] nums) {
        Arrays.sort(nums);
        int length=nums.length,count=0;
        for (int i=0;i<length;i++){
            for (int j=i+1;j<length;j++){
                int k=j+1;
                while (k<length&&nums[i]+nums[j]>nums[k]) {
                    k++;
                    count++;
                }
            }
        }
        return count;
    }
}

class Question617{
    public TreeNode process(TreeNode root1,TreeNode root2){
        TreeNode result=new TreeNode();
        if (root1==null&&root2==null) return null;//均为空时
        else if (root1!=null&&root2==null) {
            result.val= root1.val;
            result.left=process(root1.left,null);
            result.right=process(root1.right,null);
        }
        else if (root1==null&&root2!=null) {
            result.val= root2.val;
            result.left=process(null,root2.left);
            result.right=process(null,root2.right);
        }
        else {
            result.val = root1.val + root2.val;
            result.left = process(root1.left, root2.left);//左孩子
            result.right = process(root1.right, root2.right);//右孩子
        }
        return result;
    }
    public TreeNode mergeTrees(TreeNode root1, TreeNode root2) {
        return process(root1,root2);
    }
}